package com.example.mq.consumer;
import cn.hutool.json.JSONUtil;
import com.example.dto.OrderMsg;
import com.example.mq.dto.Msg;
import com.example.mq.po.MsgConsumePO;
import org.springframework.amqp.core.Message;
import org.springframework.stereotype.Component;
import java.util.concurrent.TimeUnit;

/*
@description:
@ClassName TestConsumer
@author chen
@create 2025-08-25 19:47
@Version 1.0
*/
@Component
public class TestConsumer extends AbstractSequentialMsgConsumer<OrderMsg, Msg<OrderMsg>>
{

    @Override
    protected void consume(Message message, Msg<OrderMsg> msg, MsgConsumePO msgConsumerPO)
    {
        super.dispose(message);
    }

    @Override
    protected void sequentialMsgConsume(Msg<OrderMsg> msg)
    {
        String log = "☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆顺序消息消费,消息编号：" + msg.getSequentialMsgNumbering() + ",消息体：" + JSONUtil.toJsonStr(msg.getBody());
        System.err.println(log);
        //这里休眠500ms，模拟耗时的业务操作
        try
        {
            TimeUnit.MILLISECONDS.sleep(500);
        } catch (InterruptedException e)
        {
            throw new RuntimeException(e);
        }
    }
}
